using System;

using System.Text;

namespace P2PGrid
{
    class MessagerProcessor
    {
        /// <summary>
        /// use it to do network operation 
        /// </summary>
        private INetworkOperator netOperation;

        public MessagerProcessor(INetworkOperator ino)
        {
            netOperation = ino;
        }

        public void Process(string command)
        {

            string [] commands=command.Split(' ');
            int count = commands.Length;
            if (count > 0)
            {
                string first=commands[0].ToLower();

                if (first == "start"&&(count==2))
                {
                    netOperation.Start(int.Parse(commands[1]));
                }
                if (first == "connect" && (count==2||count==3) )
                {
                    if (count == 2)
                        netOperation.Connect("127.0.0.1", int.Parse(commands[1]));
                    else
                        netOperation.Connect(commands[1],int.Parse(commands[2]));
                }
                if (first == "close" && (count == 1))
                {
                    netOperation.CloseClient();
                }
                if (first == "get" && (count == 3))
                {
                    netOperation.Send(command);
                }
                if (first == "set" && (count == 4))
                {
                    netOperation.Send(command);
                }
            }
        }

       
    }
}
